package com.csst.action;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.csst.bean.Order;
import com.csst.service.OrderService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 接收商城传来的订单信息，放在一个order对象中，保存到session中
 * 
 * 
 * @author 
 * 
 */
@Controller
public class OrderAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String sellerId;
	private String buyerId;
	private String identNum;
	private String money;
	@Autowired
	private OrderService orderService;


	public String getIdentNum() {
		return identNum;
	}

	public void setIdentNum(String identNum) {
		this.identNum = identNum;
	}


	public String getSellerId() {
		return sellerId;
	}

	public void setSellerId(String sellerId) {
		this.sellerId = sellerId;
	}

	public String getBuyerId() {
		return buyerId;
	}

	public void setBuyerId(String buyerId) {
		this.buyerId = buyerId;
	}

	public String getMoney() {
		return money;
	}

	public void setMoney(String money) {
		this.money = money;
	}


	@Override
	public String execute() throws Exception{
		if (!sellerId.equals("")&&!buyerId.equals("")&&!identNum.equals("")) {
			    Order order=new Order();
			    order.setSellerId(Integer.parseInt(sellerId));
		        order.setBuyerId(Integer.parseInt(buyerId));
		        order.setIdentNum(identNum);
		        order.setMoney(Double.parseDouble(money));
		        order.setState(1);
		        Date date=new Date();
		        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		        String otime=dateFormat.format(date);
		        order.setOtime(otime);	
		        orderService.saveOrder(order);
		        ActionContext context=ActionContext.getContext();
		        context.getSession().put("order", order);
				return SUCCESS;
		}
       return "fail";
	}

	

}
